<template>
  <div class="msgBody wap">
    <x-header  class="whiteTheme" :left-options="{backText: '',preventGoBack:true}" @on-click-back="goHome">消息中心</x-header>
    <div class="list main">
      <div class="itemBox">
        <div class="listItem lineButton" @click="goPage(1)">
          <div class="item display-flex flex-direction-row align-items-center justify-content-flex-justify">
            <div class="itemL display-flex flex-direction-row">
              <img class="itemIcon" src="../../assets/img/order/icon_sales@2x.png" alt="">
              <div class="itemContent">
                <p>促销活动</p>
                <span>{{activeTitle}}</span>
              </div>
            </div>
            <div class="itemR display-flex flex-direction-row">
              <p class="msgCount" v-if="listData.unReadActivityMessageCount>0">{{listData.unReadActivityMessageCount}}</p>
              <img class="moreIcon" src="../../assets/img/order/more@2x.png" alt="">
            </div>
          </div>
        </div>
        <div class="listItem" @click="goPage(2)">
          <div class="item display-flex flex-direction-row align-items-center justify-content-flex-justify">
            <div class="itemL display-flex flex-direction-row">
              <img class="itemIcon" src="../../assets/img/order/icon_order@2x.png" alt="">
              <div class="itemContent">
                <p>订单消息</p>
                <span v-if="listData.nextOrderMessage&&listData.nextOrderMessage!=null">{{listData.nextOrderMessage.orderStateMessageDesc}}</span>
              </div>
            </div>
            <div class="itemR display-flex flex-direction-row">
              <p class="msgCount" v-if="listData.unReadOrderMessageCount>0">{{listData.unReadOrderMessageCount}}</p>
              <img class="moreIcon" src="../../assets/img/order/more@2x.png" alt="">
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
    export default {
        name: "messageCenter",
        data(){
          return{
            listData:{},
            activeTitle:''
          }
        },
        mounted(){
            this.initData();
        },
        methods:{
          initData(){
            //message/center
            this.$ajax.get('message/center',(res)=>{
              if(res.code == '200'){
                this.listData = res.data;
                if(res.data.nextActivityMessage){
                  if(res.data.nextActivityMessage.redPacketActivityForMessageVO&&res.data.nextActivityMessage.redPacketActivityForMessageVO!=null){
                    this.activeTitle = '【红包】满'+res.data.nextActivityMessage.redPacketActivityForMessageVO.orderAmount+'减'
                      +res.data.nextActivityMessage.redPacketActivityForMessageVO.value;
                  }

                  if(res.data.nextActivityMessage.specialPriceActivityForMessageVOS&&res.data.nextActivityMessage.specialPriceActivityForMessageVOS!=null){
                    this.activeTitle = '【特价】'+res.data.nextActivityMessage.buyGoods.name+'特价抢购中！';
                  }

                  if(res.data.nextActivityMessage.fullGifActivityForMessageVO&&res.data.nextActivityMessage.fullGifActivityForMessageVO!=null){
                    this.activeTitle = '【搭赠】';
                    for (let i=0;i<res.data.nextActivityMessage.fullGifActivityForMessageVO.activityFullRuleVOList.length;i++){
                      var gifRule = '满'+res.data.nextActivityMessage.fullGifActivityForMessageVO.activityFullRuleVOList[i].num+'赠'
                        +res.data.nextActivityMessage.fullGifActivityForMessageVO.activityFullRuleVOList[i].giftNum
                        +res.data.nextActivityMessage.fullGifActivityForMessageVO.activityFullRuleVOList[i].unitName+' ';
                      this.activeTitle += gifRule;
                    }

                  }
                }
              }
            });
          },
          goPage(type){

            this.readMsg(type);
            if(1==type){
              if(this.$fromApp(this)){
                //促销活动
                // this.$callJava({url:this.$webUrl+"message/salesPromotion"});
                this.$router.push({path:'/message/salesPromotion'});
              }else{
                this.$router.push({path:'/message/salesPromotion'});
              }
            }else if(2==type){
              if(this.$fromApp(this)){
                //订单中心
                // this.$callJava({url:this.$webUrl+"message/orderCenter"});
                this.$router.push({path:'/message/orderCenter'})
              }else{
                this.$router.push({path:'/message/orderCenter'})
              }
            }
          },
          readMsg(type){
            this.$ajax.post('message/readMessage',{type:type},(res)=>{
              if(res.code == '200'){
                console.log('=w=w=w=w=',res);
              }else{
                this.$vux.toast.text(res.msg, 'center');
              }
            })
          },
          goHome(){
            if (this.$fromApp(this)){
              this.$callJava({code:1007})
            }
          }
        }
    }
</script>

<style lang="less" type="text/less" scoped>
  .msgBody{
    .list{
      border-top: 1px solid #eeeeee;
      .itemBox{
        background-color: #ffffff;
        .listItem{
          height: 1.48rem;
          margin-left: .3rem;
          .item{
            padding-top: .34rem;
            .itemL{
              .itemIcon{
                width: .8rem;
                height: .8rem;
                margin-right: .2rem;
              }
              .itemContent{
                margin-top: -0.1rem;
                p{
                  font-size: 16px;
                  font-weight: 500;
                  color: #222222;
                }
                span{
                  font-size: 12px;
                  color: #999999;
                }
              }
            }
            .itemR{
              .msgCount{
                background-color: #FF3C4A;
                color: #ffffff;
                width: .36rem;
                height: .36rem;
                border-radius: 50%;
                font-size: 10px;
                margin-top: -0.05rem;
                text-align: center;
              }
              .moreIcon{
                width: .16rem;
                height: .32rem;
                margin-right: .3rem;
                margin-left: .1rem;
              }
            }
          }
        }
        .lineButton{
          border-bottom: 1px solid #EBEBEB;
        }
      }
    }
  }
</style>
